#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T;
int n;
int ans;
int a[N];
int vis[N];
void dfs(int dep,int sum){// red 1   blue 2
	if(dep>n){
		ans=max(ans,sum);
		return;
	}
	if(dep==1){
		vis[dep]=1;
		dfs(dep+1,sum);
		vis[dep]=2;
		dfs(dep+1,sum);
	}
	else{
		vis[dep]=1;
		dfs(dep+1,sum);
		for(int i=dep-1;i;i--){
			if(vis[i]==1){
				if(a[dep]==a[i]) dfs(dep+1,sum+a[i]);
				break;
			}
		}
		vis[dep]=2;
		dfs(dep+1,sum);
		for(int i=dep-1;i;i--){
			if(vis[i]==2){
				if(a[i]==a[dep]) dfs(dep+1,sum+a[i]);
				break;
			}
		}
}
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while(T--){
		ans=0;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		dfs(1,0);
		cout<<ans<<'\n';
	}
	return 0;
}
